<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>开店信息填写</title>
    <script type="text/javascript" src="../files/js/base.js"></script>
    <link rel="stylesheet" type="text/css" href="../files/css/layui.css" media="all">
	<link rel="stylesheet" href="../files/setupshop/place/css.css" />
	<link rel="stylesheet" href="../files/setupshop/place/form.css" />
	<script type="text/javascript" src="../files/js/jquery.min.js"></script>
	<script src="../files/setupshop/place/kit.js"></script>
	<script type="text/javascript">
		var _gaq = _gaq || [];
		_gaq.push(['_setAccount', 'UA-30210234-1']);
		_gaq.push(['_trackPageview']);
		(function() {
			var ga = document.createElement('script');
			ga.type = 'text/javascript';
			ga.async = true;
			ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
			var s = document.getElementsByTagName('script')[0];
			s.parentNode.insertBefore(ga, s);
		})();
		
		$(function(){
    		var url = getRootPath()+"shop/phone.action";
    		$.get(url,null,function(phone){
    			$("#phone").val(phone);
    		},'json')
    	})
	</script>
	<script src="../files/setupshop/place/dom.js"></script>
	<script src="../files/setupshop/place/event.js"></script>
	<script src="../files/setupshop/place/TreeDict.js"></script>
	<script src="../files/setupshop/place/math.js"></script>
	<script src="../files/setupshop/place/form.js"></script>
	<script src="../files/setupshop/place/combobox.js"></script>
	<script src="../files/setupshop/place/suggestselect.js"></script>
	<script src="../files/setupshop/place/list.js"></script>
	<!--json data-->
	<script src="../files/setupshop/place/json-data.js" charset="utf-8"></script>
	
</head>

<body>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>开店信息</legend>
    </fieldset>
    <form class="layui-form" action="../shop/saveOrUpdate.action?type=1" enctype="multipart/form-data" method="post">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">店铺名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="shopName" id="shopName" required lay-verify="required" placeholder="店铺名称" autocomplete="off" class="layui-input" maxlength="20">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">店长账号</label>
                <div class="layui-input-inline">
            		<input type="text" name="linkman" id="linkman" required lay-verify="required" maxlength="11" placeholder="后台管理员账号" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">商家电话</label>
                <div class="layui-input-inline">
                    <input type="number" readonly="readonly" name="phone" id="phone" required lay-verify="required" placeholder="商家电话" autocomplete="off" class="layui-input" maxlength="11">
                </div>
            </div>
        </div>
        <script type="text/javascript">
        /* 
         * 判断图片类型 
         * @param ths type="file"的javascript对象 
         * @return true-符合要求,false-不符合 
         */  
        function checkImgType(ths){
            if (!/\.(jpg|jpeg|png|JPG|PNG)$/.test(ths.value) && ths.value != null && ths.value != "") {  
                $(".hint-img").html("图片类型必须是.jpeg,jpg,png中的一种");
                ths.value = "";  
                return false;  
            } else {
            	$(".hint-img").html("");
            }
            return true;  
        }  
        </script>
		<div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">上传图片</label>
                <div class="layui-input-inline">
		  			<input type="file" required="required" onblur="checkImgType(this)" name="image">
                </div>
                <span class="hint-img" style="color:red"></span>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">餐馆类型</label>
                <div class="layui-input-inline">
                    <select name="typeId" required lay-verify="required" id="typeId">
                        <option value="0">--请选择--</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div>
                <label class="layui-form-label">餐馆地址</label>
				<ul>
					<li>
						<span> 省份 </span>
						<select id="address1"  lay-filter="business" name="address1" required lay-verify="required" class="kitjs-form-suggestselect"></select>
						<span> 市/县 </span>
						<select id="address2"  lay-filter="business" name="address2" required lay-verify="required" class="kitjs-form-suggestselect"></select>
						<span> 区 </span>
						<select id="address3" lay-filter="business" name="address3" required lay-verify="required" class="kitjs-form-suggestselect"></select>
					</li>
				</ul>
				<script>
					var a = $kit.els8cls($kit.ui.Form.ComboBox.Select.defaultConfig.transformCls), a1 = [];
					for(var i = 0; i < a.length; i++) {
						a1.push(a[i])
					}
					a = a1;
					var b1 = new $kit.ui.Form.ComboBox.Select({
						el : a[0],
						data : (function() {
							var provTreeDict = new TreeDict();
							for(var prov in chinaJSON) {
								provTreeDict.ad(prov, prov);
							}
							return provTreeDict;
						})()
					});
					b1.transform();
					b1.ev({
						ev : 'change',
						fn : function() {
							var prov = chinaJSON[b1.inputEl.value];
							if(prov == null) {
								return;
							}
							var cityTree = new TreeDict();
							for(var city in prov) {
								cityTree.ad(city, city);
							}
							b2.inputEl.value = '';
							b2.formEl.value = '';
							b2.config.data = cityTree;
							b2.list.buildList(cityTree.search(''));
						}
					});
					var b2 = new $kit.ui.Form.ComboBox.Select({
						el : a[1],
						data : undefined
					});
					b2.transform();
					b2.ev({
						ev : 'change',
						fn : function() {
							var city = chinaJSON[b1.inputEl.value][b2.inputEl.value];
							if(city == null) {
								return;
							}
							var districtTree = new TreeDict();
							for(var district in city) {
								districtTree.ad(district, city[district]);
							}
							b3.inputEl.value = '';
							b3.formEl.value = '';
							b3.config.data = districtTree;
							b3.list.buildList(districtTree.search(''));
						}
					});
					var b3 = new $kit.ui.Form.ComboBox.Select({
						el : a[2],
						data : undefined
					});
					b3.transform();
		
				</script>
						
                <input type="hidden" id="shopSite" name="shopSite">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">详细地址</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" name="merchantCredit"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-demo"></div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="submit" class="layui-btn" lay-submit="" lay-filter="Add" value="提交">
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <script src="../files/js/layui.js"></script>
    <script src="../files/js/lay/modules/tree.js"></script>
    <script type="text/javascript">
        layui.use('form', function() {
            var form = layui.form,
                layer = layui.layer,
                $ = layui.$;
            form.on('submit(Add)', function() {
                parent.location.reload(); // 父页面刷新
            });
            var address1 = $("#address1").val();
            var address2 = $("#address2").val();
            var address3 = $("#address3").val();
            form.on('select(business)', function(data) {
            	alert("进入");
                $("#shopSite").val(address1 + "-" + address2 + "-" + address3);
            });
            
            var url = getRootPath()+"type/findType.action";
    		$.ajax({
    			url:url,
    			data:null,
    			type:'post',
    			dataType:'json',
    			async:true,  //设置为异步,如果为false,则为同步
    			success:function(mes){
    				
    				$.each(mes,function(index,item){
    					$("#typeId").append("<option value='"+item.typeId+"'>"+item.typeName+"</option>");
    				})
    				form.render();
    			},
    			error:function(){
    				console.error("服务器发生错误!");
    			}
    		});
            
        });
    </script>
</body>

</html>